PROJECT_NAME := main
PROJECT_ROOT := $(CURDIR)
SRC_DIRS := src \
			src/fileCommand \
			src/programLog \
			src/dataBase
INC_DIRS := include \
			src/fileCommand/include \
			src/programLog/include \
			src/dataBase/include
SRC_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))


# 目标文件目录
OBJ_DIR := obj
OBJ_FILES := $(patsubst %.c, $(OBJ_DIR)/%.o, $(SRC_FILES))

CC := gcc
CFLAGS := -g -Wall -O0 $(foreach dir, $(INC_DIRS), -I$(PROJECT_ROOT)/$(dir)) 
LDFLAGS := -lpthread -lmysqlclient

$(PROJECT_NAME): $(OBJ_FILES)
	$(CC) -o $@ $^ $(LDFLAGS)

$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
	@mkdir -p $(dir $@)
	$(CC) -c $< -o $@ $(CFLAGS) 


clean: 
	@echo "cleaning all generated files..."
	rm -rf $(OBJ_DIR)/src $(PROJECT_NAME)

print:
	@echo "SOURCE FILES:"
	@echo $(SRC_FILES)
	@echo "OBJECT FILES:"
	@echo $(OBJ_FILES)
	

.PHONY: all clean print

all: $(PROJECT_NAME)